<template>
 <div class="employRoster-search-table">
    <el-table
      :data="tableDatas_com"
      border
       @row-click='handleRowClick'
      :row-class-name = 'handleRowClass'
      max-height='500'
      style="width: 100%">

    <el-table-column
      style='cursor: pointer'
      v-for='(k,i) in tableOptionSelect'
      :label='k.label'
      :prop='k.value'
      :min-width='addWidth(k.value) || handleTitleWidth(k.label.length)'
      align='center'
      >
    </el-table-column>

  </el-table>
 </div>
</template>

<script>
import { _encode} from '@/common/js/handleCode'
export default {
	props: {
		tableOptionSelect: {
			default: []
		},
		tableDatas: {
			default: []
		}
	},
	computed: {


		tableDatas_com () {
			let result = []

			this.tableDatas.forEach((ele, index, arr) => {
				result.push(ele)
				result[index].xh = index + 1

				if (
					result[index].start_dt_chn &&
          result[index].start_dt_chn.length >= 10
				) {
					result[index].start_dt_chn = result[index].start_dt_chn.substring(
						0,
						10
					)
				}

				if (
					result[index].org_inst_srv_dt &&
          result[index].org_inst_srv_dt.length >= 10
				) {
					result[index].org_inst_srv_dt = result[
						index
					].org_inst_srv_dt.substring(0, 10)
				}
				if (
					result[index].cmpny_seniority_dt &&
          result[index].cmpny_seniority_dt.length >= 10
				) {
					result[index].cmpny_seniority_dt = result[
						index
					].cmpny_seniority_dt.substring(0, 10)
				}
				if (result[index].service_dt && result[index].service_dt.length >= 10) {
					result[index].service_dt = result[index].service_dt.substring(0, 10)
				}
				if (
					result[index].seniority_pay_dt &&
          result[index].seniority_pay_dt.length >= 10
				) {
					result[index].seniority_pay_dt = result[
						index
					].seniority_pay_dt.substring(0, 10)
				}
				if (
					result[index].probation_dt &&
          result[index].probation_dt.length >= 10
				) {
					result[index].probation_dt = result[index].probation_dt.substring(
						0,
						10
					)
				}
				if (
					result[index].termination_dt &&
          result[index].termination_dt.length >= 10
				) {
					result[index].termination_dt = result[index].termination_dt.substring(
						0,
						10
					)
				}
				if (result[index].birthdate && result[index].birthdate.length >= 10) {
					result[index].birthdate = result[index].birthdate.substring(0, 10)
				}
				if (result[index].c_demob_dt && result[index].c_demob_dt.length >= 10) {
					result[index].c_demob_dt = result[index].c_demob_dt.substring(0, 10)
				}
				if (
					result[index].political_effdt &&
          result[index].political_effdt.length >= 10
				) {
					result[index].political_effdt = result[
						index
					].political_effdt.substring(0, 10)
				}
				if (result[index].dt_issued && result[index].dt_issued.length >= 10) {
					result[index].dt_issued = result[index].dt_issued.substring(0, 10)
				}
				if (result[index].visa_dt && result[index].visa_dt.length >= 10) {
					result[index].visa_dt = result[index].visa_dt.substring(0, 10)
				}
				if (
					result[index].c_visa_issue_dt &&
          result[index].c_visa_issue_dt.length >= 10
				) {
					result[index].c_visa_issue_dt = result[
						index
					].c_visa_issue_dt.substring(0, 10)
				}

				if (result[index].visa_permit_type == 'null') {
					result[index].visa_permit_type = ''
				}
				if (result[index].group_nbr == 'null') {
					result[index].group_nbr = ''
				}

				if (result[index].dt_issued == 'null') {
					result[index].dt_issued = ''
				}

				if (result[index].duration_type == 'null') {
					result[index].duration_type = ''
				}

				if (result[index].passport_nbr == 'null') {
					result[index].passport_nbr = ''
				}

				if (result[index].visa_dt == 'null') {
					result[index].visa_dt = ''
				}

				if (result[index].c_visa_issue_dt == 'null') {
					result[index].c_visa_issue_dt = ''
				}
			})

			return result

			// this.tableDatas.forEach((ele, index, arr) => {

			//   if (ele.start_dt_chn && ele.start_dt_chn.length >= 10) {
			//     ele.start_dt_chn = ele.start_dt_chn.substring(0, 10)
			//   }

			//   if (ele.org_inst_srv_dt && ele.org_inst_srv_dt.length >= 10) {
			//     ele.org_inst_srv_dt = ele.org_inst_srv_dt.substring(0, 10)
			//   }
			//   if (ele.cmpny_seniority_dt && ele.cmpny_seniority_dt.length >= 10) { ele.cmpny_seniority_dt = ele.cmpny_seniority_dt.substring(0, 10) }
			//   if (ele.service_dt && ele.service_dt.length >= 10) { ele.service_dt = ele.service_dt.substring(0, 10) }
			//   if (ele.seniority_pay_dt && ele.seniority_pay_dt.length >= 10) { ele.seniority_pay_dt = ele.seniority_pay_dt.substring(0, 10) }
			//   if (ele.probation_dt && ele.probation_dt.length >= 10) { ele.probation_dt = ele.probation_dt.substring(0, 10) }
			//   if (ele.termination_dt && ele.termination_dt.length >= 10) { ele.termination_dt = ele.termination_dt.substring(0, 10) }
			//   if (ele.birthdate && ele.birthdate.length >= 10) { ele.birthdate = ele.birthdate.substring(0, 10) }
			//   if (ele.c_demob_dt && ele.c_demob_dt.length >= 10) { ele.c_demob_dt = ele.c_demob_dt.substring(0, 10) }
			//   if (ele.political_effdt && ele.political_effdt.length >= 10) { ele.political_effdt = ele.political_effdt.substring(0, 10) }
			//   if (ele.dt_issued && ele.dt_issued.length >= 10) { ele.dt_issued = ele.dt_issued.substring(0, 10) }
			//   if (ele.visa_dt && ele.visa_dt.length >= 10) { ele.visa_dt = ele.visa_dt.substring(0, 10) }
			//   if (ele.c_visa_issue_dt && ele.c_visa_issue_dt.length >= 10) { ele.c_visa_issue_dt = ele.c_visa_issue_dt.substring(0, 10) }

			//   if (ele.visa_permit_type == 'null') {
			//     ele.visa_permit_type = ''
			//   }
			//   if (ele.group_nbr == 'null') {
			//     ele.group_nbr = ''
			//   }

			//   if (ele.dt_issued == 'null') {
			//     ele.dt_issued = ''
			//   }

			//   if (ele.duration_type == 'null') {
			//     ele.duration_type = ''
			//   }

			//   if (ele.passport_nbr == 'null') {
			//     ele.passport_nbr = ''
			//   }

			//   if (ele.visa_dt == 'null') {
			//     ele.visa_dt = ''
			//   }

			//   if (ele.c_visa_issue_dt == 'null') {
			//     ele.c_visa_issue_dt = ''
			//   }

			// })

			// return this.tableDatas
		}
	},

	data () {
		return {}
	},

	methods: {

		handleRowClass (data) {
			if (parseInt(data.personnel) !== 1) return 'not-allowed'
			return 'pointer'
		},

		handleRowClick (data) {
			if (parseInt(data.personnel) !== 1) return
			let sex = data.sex == 'F' ? 2 : 1
			const params = {
				emplid: data.emplid,
				resumeType: 2,
				sex
			}

			window.open('/module/resume.html?' + _encode(JSON.stringify(params)))
			// localStorage.setItem('em',(data.emplid))
			// localStorage.setItem('resumeType', 2)
			// localStorage.setItem('em_sex', data.sex == 'F' ? 2 : 1)

		},

		addWidth (val) {

			if (val == 'emplid') {
				return 100
			}
			if ((val == 'business_descr')) {
				return 200
			}
			if ((val == 'dept_descr')) {
				return 180
			}
			if ((val == 'position_desc')) {
				return 280
			}
			if ((val == 'jobcode_desc')) {
				return 150
			}
			if ((val == 'grp_lvl_descr')) {
				return 220
			}
			if ((val == 'sta_lvl_descr')) {
				return 220
			}
			if ((val == 'empl_class_desc')) {
				return 140
			}
			if ((val == 'posn_clan_desc')) {
				return 140
			}
			if ((val == 'birthcountry_desc')) {
				return 100
			}
			if ((val == 'busn_mobile')) {
				return 130
			}
			if ((val == 'home_address')) {
				return 300
			} else {
				return false
			}


		},
		handleTitleWidth (len) {
			if (len < 4) {
				return 80
			} else if (len >= 4 && len <= 6) {
				return len * 30
			} else if (len > 6) {
				return len * 20
			}
		}
	}
}
</script>

<style lang='less'>
.employRoster-search-table {
  padding: 15px 15px 30px 15px;
}

.not-allowed {
  cursor: not-allowed;
}

.pointer {
  cursor: pointer;
}
</style>
